package com.mao.crowd.service.impl;

import com.mao.crowd.entity.po.Address;
import com.mao.crowd.entity.po.AddressExample;
import com.mao.crowd.entity.vo.AddressVO;
import com.mao.crowd.entity.vo.OrderProjectVO;
import com.mao.crowd.mapper.AddressMapper;
import com.mao.crowd.mapper.OrderMapper;
import com.mao.crowd.mapper.OrderProjectMapper;
import com.mao.crowd.service.api.OrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;


/**
 * @author: Administrator
 * @description:
 * @cteate 2021-06-28-21:41
 */
@Transactional(readOnly = true)
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderProjectMapper orderProjectMapper;

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private AddressMapper addressMapper;


    @Override
    public OrderProjectVO getOrderProjectVO(Integer projectId, Integer returnId) {

        OrderProjectVO orderProjectVO = orderProjectMapper.selectOrderProjectVO(returnId);


        return orderProjectVO;
    }

    @Override
    public List<AddressVO> getAddressVOList(Integer memberId) {

        AddressExample addressExample = new AddressExample();
        addressExample.createCriteria().andMemberIdEqualTo(memberId);
        List<Address> addresses = addressMapper.selectByExample(addressExample);

        List<AddressVO> addressVOList = new ArrayList<>();
        for (Address address : addresses){
            AddressVO addressVO = new AddressVO();
            BeanUtils.copyProperties(address,addressVO);
            addressVOList.add(addressVO);
        }

        return addressVOList;
    }
}
